package org.meow.controller.api;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.meow.entity.News;
import org.meow.result.Result;
import org.meow.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * &#064;Date: 24/05/16-13:50
 * &#064;Description:
 */
@RestController
@RequestMapping("/api/news")
@Tag(name = "API接口")
public class NewsApi {
  @Autowired
  private NewsService newsService;

  @GetMapping
  @Operation(summary = "获取新闻列表")
  public Result<List<News>> getNews() {
    return Result.success(newsService.getNewsList());
  }

  @GetMapping("/{id}")
  @Operation(summary = "获取指定id新闻")
  public Result<Object> getNewsById(@PathVariable Integer id) {
    News news = newsService.getNewsById(id);
    return news == null ? Result.error("该新闻不存在") : Result.success(news);
  }

}
